#include<bits/stdc++.h>
#define lowbit(i) i&(-i)
#define int long long
using namespace std;
const int maxn=11114514;
int A[maxn],n,r,B[maxn],a[maxn],b[maxn];
map<int,int>C;
map<int,int>C2;
map<int,int>D;
map<int,int>E; 
void add(int x,int y){while(x<=r){C[x]+=y;x+=lowbit(x);}}
int sum(int x){int ans=0;while(x>0){ans+=C[x];x-=lowbit(x);}return ans;}
void add2(int x,int y){while(x<=r){C2[x]+=y;x+=lowbit(x);}}
int sum2(int x){int ans=0;while(x>0){ans+=C2[x];x-=lowbit(x);}return ans;}
signed main(){
	int m;
	cin>>n;
	for(int i=1;i<=n;i++){
	cin>>A[i];
	r=max(r,A[i]);
	B[n-i+1]=A[i];
	}
	for(int i=1;i<=n;i++){
		add(A[i],1);
		a[i]=sum(A[i]-1);
		//cout<<a[i]<<endl;
	}
	for(int i=1;i<=n;i++){
		D[B[i]]++;
		add2(B[i],1);
		b[i]=i-sum2(B[i]-1)-D[B[i]];
		//cout<<b[i]<<endl;
	}
	long long ans=0;
	for(int i=1;i<=n;i++){
		ans+=a[i]*b[n-i+1];
	}
	C.clear();
	C2.clear();
	D.clear();
	for(int i=1;i<=n/2;i++){
		swap(A[i],A[n-i+1]);
	}
	for(int i=1;i<=n;i++){
	r=max(r,A[i]);
	B[n-i+1]=A[i];
	}
	for(int i=1;i<=n;i++){
		add(A[i],1);
		a[i]=sum(A[i]-1);
		//cout<<a[i]<<endl;
	}
	for(int i=1;i<=n;i++){
		D[B[i]]++;
		add2(B[i],1);
		b[i]=i-sum2(B[i]-1)-D[B[i]];
	}
	for(int i=1;i<=n;i++){
		ans+=a[i]*b[n-i+1];
	}
	cout<<ans<<endl;
	return 0;
}